<?php
/**
 * 解释和生成 email的xml格式
 * 
 * modifiedOn 2010-10-25 oushunbao
 * 
 */
class emailFormat
{
	  var $to_list,$sending_account_id,$from_name,$from_email,$reply_to_name,$replay_to_email,
	  		$email_subject,$email_content, $email_attachments;
	  
	  function emailFormat($to_list='',$sending_account_id='',$from_name='',$from_email='',
	  		$reply_to_name='',$reply_to_email='',$email_subject='',$email_content='', $email_attachments = array()){
	  			
		  	$this->to_list=$to_list;
		  	$this->sending_account_id=$sending_account_id;
		  	$this->from_name=$from_name;
		  	$this->from_email=$from_email;
		  	$this->reply_to_name=$reply_to_name;
		  	$this->reply_to_email=$reply_to_email;
		  	$this->email_subject=$email_subject;
		  	$this->email_content=$email_content;
		  	$this->email_attachments=$email_attachments;
	  }
	  
	  function buildEmail(){
	  	    $email_xml  ='<?xml version="1.0" encoding = "UTF-8"?>';
	  	    $email_xml .='<email>';
	  	    $email_xml .='<to_list>';
	  	    foreach ($this->to_list as $to_info){
	  	         $email_xml .='<to_info>'; 	
	  	         $email_xml .='<to_name><![CDATA['.$to_info['to_name'].']]></to_name>';
	  	         $email_xml .='<to_email><![CDATA['.$to_info['to_email'].']]></to_email>';
	  	         $email_xml .='</to_info>';
	  	    }
	  	    $email_xml  .='</to_list>';
	  	    $email_xml  .='<sending_account_id><![CDATA['.$this->sending_account_id.']]></sending_account_id>';
	  	    $email_xml  .='<from_name><![CDATA['.$this->from_name.']]></from_name>';
	  	    $email_xml  .='<from_email><![CDATA['.$this->from_email.']]></from_email>';
	  	    $email_xml  .='<reply_to_name><![CDATA['.$this->reply_to_name.']]></reply_to_name>';
	  	    $email_xml  .='<reply_to_email><![CDATA['.$this->reply_to_email.']]></reply_to_email>';
	  	    $email_xml  .='<email_subject><![CDATA['.$this->email_subject.']]></email_subject>';
	  	    $email_xml  .='<email_content><![CDATA['.$this->email_content.']]></email_content>';
		    
	  	    if (count($this->email_attachments) > 0){
	  	    	$email_xml .= '<email_attachments>';
	  	    	foreach ($this->email_attachments as $attachment){
	  	    		$email_xml .= '<email_attachment><![CDATA['.$attachment.']]></email_attachment>';
	  	    	}
	  	    	$email_xml .= '</email_attachments>';
	  	    }
	  	    
	  	    
	  	    $email_xml  .='</email>';
	  	    return $email_xml;
	  }
	   
	  function parseEmail($emailXML){
	  		
	  	    $xmlParser=simplexml_load_file($emailXML);
	  	    $temp=get_object_vars($xmlParser);
	  	     while (list($key, $value) = each($temp)) {
    		    $this->$key = $value;
            }
	  }
	 
	  
	  
	  

}

?>
